package com.pss.common.exception;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;

@Data
public class BaseException extends RuntimeException {

    private int code;
    private String message;
    private ErrorCodes errorCodes;
    private HashMap<String,Object> data;

    public BaseException(String message) {
        super(message);
        this.code = ErrorCodes.SYSTEM_ERROR.getValue();
        this.message = message;
    }
    public BaseException(String message, HashMap<String,Object> data) {
        super(message);
        this.code = ErrorCodes.SYSTEM_ERROR.getValue();
        this.message = message;
        this.data = data;
    }

    public BaseException(ErrorCodes errorCode) {
        super(errorCode.getMessage());
        this.errorCodes = errorCode;
        this.code = errorCode.getValue();
        this.message = errorCode.getMessage();
    }

    public BaseException(ErrorCodes errorCode, String detailsMsg) {
        super(errorCode.getMessage());
        this.errorCodes = errorCode;
        this.code = errorCode.getValue();
        this.message = errorCode.getMessage()+" 详情："+detailsMsg;
    }

    public BaseException(int errorCode, String message) {
        super(message);
        this.code = errorCode;
        this.message = message;
    }

    public BaseException(int errorCode, String message, Object... messageArgs) {
        super(message);
        this.code = errorCode;
        this.message = message;
        if (message != null && messageArgs != null) {
            this.message = String.format(message, messageArgs);
        }
    }

    public BaseException(Throwable cause) {
        super(cause);
    }
    public BaseException(String message, Throwable cause) {
        super(cause);
    }

}
